package ModelLayer;

import java.util.ArrayList;


/**
 * the DVD class holds information about the DVDs in the collection, such as lists with copys, unique ID numbers,
 * title, arist and release dates.
 * 
 * @author (grp b) 
 * @version (6-11-2012)
 */
public class DVD
{
    // instance variables - replace the example below with your own
    private static long idCount;
    private long id;
    private String title;
    private String director;
    private String releaseDate;
    private ArrayList<Copy> copyList;
    

    /**
     * Constructor for objects of class DVD
     * 
     * @param Title is initialising the title.      Type String
     * @param director initialises director.        Type String
     * @param releaseDate initialises releasedate.  Type String
     * @param id initialises the id.                Type long
     */
    public DVD(long id, String title, String director, String releaseDate)
    {
        this.title = title;
        this.director = director;
        this.releaseDate = releaseDate;
        this.id = id;
        copyList = new ArrayList<Copy>();
    }
    
    /**
     * Set method for title
     * 
     * @param Sets title attribute for Title.
     */
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    /**
     * Get method for title
     * 
     * @return Returns the attribute for title
     */
    public String getTitle()
    {
        return title;
    }
    
    /**
     * Set method for Director
     * 
     * @param Sets the attribute for 'director'
     */
    public void setDirector(String director)
    {
        this.director = director;
    }
    
    /**
     * Get method for 'director'
     * 
     * @return Returns value for 'director'
     */
    public String getDirector()
    {
        return director;
    }
    
    /**
     * Set method for release date of the dvd
     * 
     * @param Sets the 'releaseDate' attribute
     */
    public void setReleaseDate(String releaseDate)
    {
        this.releaseDate = releaseDate;
    }
    
    /**
     * Get method for releaseDate
     * 
     * @return Returns attribute
     */
    public String getReleaseDate()
    {
        return releaseDate;
    }
    
    public long getID()
    {
        return id;
    }
    
    /**
     * Method for adding a copy to the dvd ID, so that more copys of the same DVD can be easily surveyed and found.
     */
    public void addCopy(String serialNumber, String acquisitionDate, double acquisitionPrice)
    {
        copyList.add(new Copy(serialNumber, acquisitionDate, acquisitionPrice));
    }
    
    /**
     * This method searches the Copies associated with this method, and returns a Copy with the given id. If none is found, null is returned.
     * 
     * @param   serialNumber    The serialNumber of the Copy. A String.
     * 
     * @return  An object of Copy with the given id.
     */
    public Copy findCopy(String serialNumber)
    {
        boolean found = false;
        Copy c = null;
        int i = 0;
        while(i < copyList.size() && !found)
        {
            if(copyList.get(i).getSerialNumber().equals(serialNumber))
            {
                c = copyList.get(i);
                found = true;
            }
            i++;
        }
        return c;
    }
    
    /**
     * This method detelets an object of Copy assosiated with the class.
     * 
     * @param   serialNumber    The serial of the Copy to be deleted. A String.
     */
    public void deleteCopy(String serialNumber)
    {
        boolean found = false;
        int i = 0;
        while(i < copyList.size() && !found)
        {
            if(copyList.get(i).getSerialNumber().equals(serialNumber))
            {
                copyList.remove(i);
                found = true;
            }
            i++;
        }
    }
    
    /**
     * This method rturns a list of all the Copies associated with this object.
     * 
     * @return  A list og Copy's, as an ArrayList<Copy>.
     */
    public ArrayList<Copy> listAllCopies()
    {
        return copyList;
    }
}
